package com.example.ddcoursequery;

import android.app.IntentService;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import java.util.Iterator;


public class InitStoreTeacherService extends IntentService {
    public InitStoreTeacherService() {
        super("MyIntentService");
    }

    //在这个方法中可以去处理一些具体的逻辑
    @Override
    protected void onHandleIntent(Intent intent) {
        try {
            MyDbHelper myDbHelper = new MyDbHelper(getApplicationContext(),"courses.db",null,Resources.db_version);
            SQLiteDatabase sqLiteDatabase = myDbHelper.getWritableDatabase();
            String add_course = "insert into teacher(teacher_id,teacher_name,teacher_cached) values(?,?,?);";
            if(CacheTeacher.teacherList != null && CacheTeacher.teacherList.size() != 0){
                for (AppTeacher appTeacher:CacheTeacher.teacherList){
                    String id = appTeacher.getTeacher_id();
                    String name = appTeacher.getTeacher_name();
                    boolean cached = appTeacher.isTeacher_isCached();
                    String cachedStr = cached?"true":"false";
                    sqLiteDatabase.execSQL(add_course,new String[]{id,name,cachedStr});
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
